package com.self.study.subjectsstudy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.self.study.subjectsstudy.common.ResultInfo;
import com.self.study.subjectsstudy.db.bean.Subjects;
import com.self.study.subjectsstudy.service.ISubjectsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lixunhuan
 * @since 2021-03-06
 */
@RestController
@RequestMapping("/study/subjects")
public class SubjectsController {

    @Autowired
    private ISubjectsService subjectsService;

    /**
     * 根据套数id获取题目
     *
     * @param subjectIt 套id
     * @return 结果集
     */
    @RequestMapping("subjects")
    public ResultInfo getSubjectsByItem(@RequestParam("subject_it") Integer subjectIt,
                                        @RequestParam("subject_type") Integer subjectType,
                                        @RequestParam("level") Integer level) {
        return new ResultInfo(ResultInfo.Status.SUCCESS).result(subjectsService.list(new QueryWrapper<Subjects>()
                .eq("subject_it", subjectIt).eq("subject_type", subjectType).eq("level",level)
                .orderByAsc("id")));
    }

    /**
     * 获取题目套数
     */
    @RequestMapping("items")
    public ResultInfo getItems(@RequestParam("subject_type") Integer subjectType,@RequestParam("level") Integer level) {
        return new ResultInfo(ResultInfo.Status.SUCCESS).result(subjectsService.getItems(subjectType,level));
    }

    @RequestMapping("exam")
    public ResultInfo getSubjectsByLevelAndType(@RequestParam("subject_type") Integer subjectType,
                                                @RequestParam("level") Integer level) {


        return subjectsService.getSubjectsByLevelAndType(subjectType, level);
    }
}
